home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 06 - 1990 / 06.12 Dec 90 / Windoids XCMD / Windoids.c
Encoding:
C/C++ Source or Header  |  1994-11-06  |  4.7 KB  |  225 lines  |  [TEXT/KAHL]

  1. /************************************/
  2. /* File: Donald Koscheka.c            */
  3. /*                                     */
  4. /* --------------------------------    */
  5. /* ©1990 Donald Koscheka            */
  6. /* All Rights Reserved                */
  7. /************************************/
  8.  
  9. #include    <HyperXCMD.h>
  10. #include    <HyperUtils.h>
  11. #include    <SetUpA4.h>
  12.  
  13. #ifndef    MouseMovedEvt
  14. #define        MouseMovedEvt        0xFA    /* Mouse moved event code            */
  15. #endif
  16.  
  17. #ifndef    SuspendResumeEvt
  18. #define        SuspendResumeEvt    0x01    /* Suspend/Resume event code        */
  19. #endif
  20.  
  21. #define        ResumeEvtMask        0x1        /* Supend or Resume selector        */
  22. #define        ConvertScrapMask    0x2        /* Scrap conversion flag            */
  23.  
  24.  
  25. pascal void HandleHCEvent( XCmdPtr pp);
  26. pascal void HandleHCMessage( XCmdPtr pp);
  27. pascal void UpdateWindow( WindowPtr wind );
  28. pascal void    DoContent(  WindowPtr wind, XWEventInfoPtr    ip);
  29.  
  30.  
  31.  
  32. pascal void main( pp )
  33.     XCmdPtr    pp;
  34. /************************************
  35. * MAIN ENTRY POINT
  36. ************************************/
  37. {
  38.     
  39.     pp->returnValue = NIL;
  40.         
  41.     if( pp->paramCount < 0 )
  42.         HandleHCEvent( pp );
  43.     else{
  44.         if( pp->paramCount == 1 )
  45.             if( **(pp->params[0]) == '!'  || **(pp->params[0]) == '?' ){
  46.                 switch(  **(pp->params[0]) ){
  47.                     case '!': 
  48.                         pp->returnValue = PASTOZERO( pp, "\pWindoids ©1990, 1991 Donald Koscheka, Inc.");
  49.                         return;
  50.  
  51.                     case '?':
  52.                         pp->returnValue = PASTOZERO( pp, "\pWindoids [command] <parameters>" );
  53.                         return;
  54.                 }
  55.             }
  56.         
  57.         HandleHCMessage( pp );    
  58.     }
  59.     
  60.     UnloadA4Seg( 0L );
  61.     RestoreA4();
  62. }
  63.  
  64.  
  65.  
  66. pascal void HandleHCEvent( pp )
  67.         XCmdPtr            pp;
  68. /**********************************
  69. * Handle events in our xWindows    
  70. * returns true if the event was handled ok
  71. **********************************/
  72. {
  73.     short            windoPart;
  74.     Rect            r;
  75.     XWEventInfoPtr    ip    = pp->params[0];
  76.     WindowPtr        whichWindow;
  77.     
  78.     pp->passFlag = FALSE;
  79.  
  80.     switch( ip->event.what ){
  81.         case mouseDown:
  82.             whichWindow = ip->eventWindow;
  83.             windoPart = FindWindow( ip->event.where, &whichWindow );
  84.                 
  85.             if( whichWindow )
  86.                 switch ( windoPart ){
  87.                     case inGoAway:
  88.                         if (TrackGoAway( whichWindow, ip->event.where) ){
  89.                             CLOSEXWINDOW( pp,whichWindow );
  90.                             pp->passFlag = FALSE;
  91.                         }
  92.                         break;
  93.  
  94.                     case inDrag:
  95.                         /* handled by hypercard */
  96.                         pp->passFlag = TRUE;
  97.                         break;
  98.                         
  99.                     case inGrow:
  100.                     break;
  101.                         
  102.                     case inContent:
  103.                         if (whichWindow != FrontWindow() )
  104.                             SelectWindow( whichWindow );
  105.                         else{
  106.                             DoContent( whichWindow, ip );
  107.                         }
  108.                         pp->passFlag = TRUE;
  109.                         break;
  110.                     
  111.                     default: 
  112.                         break;
  113.                 }/* window part */
  114.             break;
  115.             
  116.         case mouseUp:
  117.             break;
  118.                     
  119.         case keyDown:
  120.         case autoKey:
  121.             break;
  122.             
  123.         case activateEvt:
  124.             /* [DK] ON ACTIVATE, DRAW THE MENUS, ON DEACTIVATE HIDE THE MENUS */
  125.             if ( ip->event.modifiers & activeFlag ){
  126.                 r= (ip->eventWindow)->portRect;
  127.                 InvalRect( &r );
  128.             }
  129.             pp->passFlag = TRUE;
  130.             break;
  131.             
  132.         case updateEvt: 
  133.             UpdateWindow(  ip->eventWindow );
  134.             pp->passFlag = TRUE;
  135.             break;
  136.             
  137.         case app4Evt:
  138.              {
  139.                  unsigned    char    *evtType = &(ip->event.message);
  140.                  
  141.                  switch( *evtType ){
  142.                      case MouseMovedEvt:
  143.                      break;
  144.                      
  145.                      case SuspendResumeEvt:
  146.                          if( ip->event.message & ResumeEvtMask )
  147.                             show_all_windows();
  148.                         else
  149.                             hide_all_windows();
  150.                     break;
  151.                  }
  152.             }
  153.             pp->passFlag = TRUE;
  154.             break;
  155.         
  156.         case xOpenEvt:
  157.             ShowWindow( ip->eventWindow );
  158.             pp->passFlag = TRUE;
  159.             break;
  160.                 
  161.         case xCloseEvt:
  162.             pp->passFlag = TRUE;
  163.             break;
  164.         
  165.         default:        
  166.             break;    
  167.     } /* switch theEvent->what */
  168. }
  169.  
  170.  
  171.  
  172. pascal void    DoContent( wind, ip )
  173.         WindowPtr        wind;
  174.         XWEventInfoPtr    ip;
  175. /*************************************
  176. * Handle the content region in a mouse
  177. * down in an xwindow. ip is  a pointer
  178. * to the HyperXevent record, needed
  179. * to see where the mouse is and what the
  180. * modifiers are.
  181. *************************************/
  182. {
  183.     SetPort( wind );
  184. }
  185.  
  186.  
  187. pascal void HandleHCMessage( pp )
  188.             XCmdPtr            pp;
  189. /*****************************************
  190. * Hypercard has sent us a message which we 
  191. * need to respond to. The command is passed in
  192. * parameter 1 and the arguments are passed
  193. * in parameter 2..N
  194. *
  195. * Perhaps you'll add a little parser here
  196. * to accept valid commands and dispatch to 
  197. * the correct command handler. You may pass
  198. * a command here called "openwindow" and another
  199. * called "closewindow" to allow the user to 
  200. * create and destroy external windows. 
  201. *****************************************/
  202. {
  203. }
  204.  
  205.  
  206.  
  207. pascal void UpdateWindow( xwind )
  208.     WindowPtr    wind;
  209. /******************
  210. * Draw the contents of the window.
  211. *
  212. * You need to develop some mechanism
  213. * for storing window specific data.
  214. * You might try storing the info
  215. * in the window's refcon.  The choice
  216. * is up to you.  
  217. ******************/
  218. {
  219.     BeginUpdate( wind );
  220.     SetPort( wind );
  221.     ClipRect( &wind->portRect );
  222.     EndUpdate( wind );
  223. }
  224.  
  225.